//
//  HomeStatsView.swift
//  Crypto
//
//  Created by DaleGuo on 2023/9/23.
//

import SwiftUI

struct HomeStatsView: View {
    @EnvironmentObject private var vm: HomeViewModel

    @Binding var showPortfolio: Bool

    var body: some View {
        HStack {
            ForEach(vm.stats) { stat in
                StatisticCoinView(stat: stat)
                    .frame(width: UIScreen.main.bounds.width / 3)
            }
        }
        .frame(width: UIScreen.main.bounds.width, alignment: showPortfolio ? .trailing : .leading) // 将Stack的内容限制到屏幕内，并可以使用alignment来控制位置
    }
}

#Preview {
    HomeStatsView(showPortfolio: .constant(false))
        .environmentObject(Preview.dev.homeVM)
}
